// pages/myself/collection.js
var utils = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        collection: [],
        height: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
		// var query = wx.createSelectorQuery();
		// //选择id
		 var that = this;
		// query.select('.proheight').boundingClientRect(function (rect) {
		// 	// console.log(rect.width)
		// 	that.setData({
		// 		height: rect.width + 'px'
		// 	})
		// }).exec();
        that.getdata()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },
    getdata: function() {
        var that = this
        utils.GET({
            url: 'Member/collection',
            params: {
                //  uid: wx.getStorageSync('uid'),
                uid: 1

            },
            success: function(res) {
                console.log(res.data)
                that.setData({
                    collection: res.data.d
                })
            },
        })
    },
	selectList:function(e) {
		const index = e.currentTarget.dataset.index;
		let collection = this.data.collection;
		const selected = collection[index].selected;
		collection[index].selected = !selected;
		this.setData({
			collection: collection
		});
	}, 
	shanchu:function(){
		var that = this
		var arr = that.data.collection
		var toastStr=''
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].selected) {
				toastStr += arr[i].id;
				toastStr += ' ';

			}
		}
		utils.GET({
			url: 'Member/delc',
			params: {
				aid: toastStr,
				uid: 1
			},
			success: function (res) {
				console.log(res.data)
				that.setData({
					 collection: res.data.d
				})
			},
		})
	}
})